﻿@{
    ViewBag.Title = "字典配置";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script type="text/javascript">
    $(function () {
        btnSearch_Click(); 
    });
    var opts = {
        rows: 10,
        height: 450,
        url: "/PEPara/GetDictionaryList",
        para: { name: $("#txtName").val() },
        idField: "Guid",
        checkbox: false,
        columns: [
                    { field: 'Name', title: '名称', width: 40, sortable: true },
                    { field: 'Description', title: '描述', width: 40, sortable: true },
                    { field: 'Guid', title: '操作', align: 'center', width: 10,
                        formatter: function (value, rowData, rowIndex) {
                            var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,\"" + value + "\")' ><option value=''>-请选择-</option>";
                            doActionOptions += "<option>修改</option><option>删除</option>";
                            return doActionOptions;
                        }
                    }
                    ]
    };

    function btnAdd_Click(v, t) {
        if (t != 2)
            t = 1;
        window.location.href = "/PEPara/EditDict?type=" + t + "&id=" + v;
    }
    function ViewList(id, nm) {
        window.location.href = "/PEPara/DictList?ParentID=" + id + "&name=" + nm;
    }
    function btnSearch_Click(p) {
        opts.para["ParentID"] = "";
        opts.para["name"] = $.trim($("#txtName").val());
        if (p == 1)
            thisPageNum = 1;
        $("#DataGrid").dg(opts);
    }
    //“操作”下拉框事件
    function DoAction(i, value) {
        if (i == 1) {
            btnAdd_Click(value, 2);
        }
        else if (i == 2) {
            DeleteFun(value);
        }
    } 
    function EditFun(funID) {
        window.location.href = "/PEPara/EditDict?id=" + funID; 
    }
    function DeleteFun(id) {
        if (confirm("确定要删除吗?")) {
            $.post("/PEPara/Delete?id=" + id, function (result) {
                if (result == 1) {
                    alert("操作成功！");
                }
                else {
                    alert(result);
                }
                btnSearch_Click();
            });
        } else
            btnSearch_Click();
    }
</script>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                字典配置搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                名称：
                <input id="txtName" type="text" style="width: 200px;" /> 
                <input id="btnSearch" type="button" class="button" value=" 搜 索 " onclick="btnSearch_Click(1)" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                字典配置列表
            </td>
            <td align="right">
                <input type="button" value="新增字典" class="button" onclick="btnAdd_Click('',1);" />
                <input type="button" value="新增字典分类" class="button" onclick="btnAdd_Click('',2);" />
            </td>
        </tr>
    </table>
    <table id="DataGrid" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
